#-*- coding: utf8 -*-
from tutor.script import *
from tutor.plugin.maple import *

# variáveis úteis
half = M('1/2')
t = M.t
_i, _j, _k = M('_i, _j, _k')
rr = M('`..`')
coeff, sqrt = M.coeff, M.sqrt
r = M.r
t = M.t
M.assume(r>0)

# parâmetros iniciais
z0 = oneof(1, 2, 3, 4)
z1 = z0 + oneof(1, 2, 3, 4)

# define variáveis
X = r * cos(t)
Y = r * sin(t)
Z = r

Rr = M.Vector([diff(X, r), diff(Y, r), diff(Z, r)])
Rt = M.Vector([diff(X, t), diff(Y, t), diff(Z, t)])
JV = M('LinearAlgebra:-CrossProduct')(Rr, Rt)
JS = M.simplify(sqrt(sum( c**2 for c in M.convert(JV, M.list) )))

# calculos corretos
Mass = M.int(M.int(JS, r=rr(z0, z1)), t==rr(0, 2*Pi)) * M.delta
print('M:', Mass)

zcm = M.int(M.int(JS * Z, r=rr(z0, z1)), t=rr(0, 2*Pi)) / Mass * M.delta
print('zcm:', zcm)

Iz = M.int(M.int(JS * (X**2 + Y**2), r=rr(z0, z1)), t=rr(0, 2*Pi)) * M.delta
print('Iz:', Iz)

# erro no elemento de integracao
MAchat = Mass / 2
zcmAchat = (z1 + z0) / M(2)
IzAchat = Iz / 2

# calculos corretos
JS = 1 + (x + y) / sqrt(x**2 + y**2)
JS = subs(x==r*cos(t), y==r*sin(t), JS)
MSum = M.int(M.int(JS, r=rr(z0, z1)), t==rr(0, 2*Pi)) * M.delta
print('MSum:', MSum)

zcmSum = M.int(M.int(JS * Z, r=rr(z0, z1)), t=rr(0, 2*Pi)) / Mass * M.delta
print('zcmSum:', zcmSum)

IzSum = M.int(M.int(JS * (X**2 + Y**2), r=rr(z0, z1)), t=rr(0, 2*Pi)) * M.delta
print('IzSum:', IzSum)
